/*
 * @lc app=leetcode.cn id=1137 lang=typescript
 *
 * [1137] 第 N 个泰波那契数
 */

// @lc code=start
function tribonacci(n: number): number {
    if (n < 2) return n;
    if (n === 2) return 1;
    let last_0 = 0;
    let last_1 = 1;
    let last_2 = 1;
    let now = 3;
    while (now <= n) {
        [last_2, last_1, last_0] = [last_0 + last_1 + last_2, last_2, last_1];
        now++;
    }
    return last_2;
}
// @lc code=end
